package com.scau.service.impl;

import com.scau.common.exception.BusinessException;
import com.scau.dao.FollowRecordDao;
import com.scau.entity.FollowRecord;
import com.scau.service.FollowRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class FollowRecordServiceImpl implements FollowRecordService {

    @Autowired
    private FollowRecordDao followRecordDao;
    @Override
    public void add(FollowRecord followRecord) {

        FollowRecord cache = followRecordDao.save(followRecord);
        BeanUtils.copyProperties(cache, followRecord);
    }

    @Override
    public FollowRecord findOne(Long followRecordId) {
        FollowRecord followRecord = followRecordDao.findOne(followRecordId);

        if (followRecord == null) {
            throw new BusinessException("没有该跟踪记录");
        }
        return followRecord;
    }

    @Override
    public Page<FollowRecord> findAll(FollowRecord followRecord, Pageable pageable) {
        return followRecordDao.findAll(Example.of(followRecord), pageable);
    }
}
